/*
 * Motor_Driver.c
 *
 * Created: 4/5/2013 9:07:32 AM
 *  Author: Parag
 * this version includes the Motor Adjust;
 */ 
#include "Motor_Driver.h"



void MotorInit()
{
	DDR_Motor |= (1<<P_Pump) | (1<<P_Solenoid) | (1<<P_Invert);             
}

void MotorOnForward()
{
	PORT_Motor &= ~(1<<P_Invert);                                                     
	PORT_Motor |= ((1<<P_Solenoid) |(1<<P_Pump));
}

void MotorOnBack()
{
	PORT_Motor |= (1<<P_Invert);
	PORT_Motor |= ((1<<P_Solenoid) |(1<<P_Pump));
}

void MotorOff()
{
	PORT_Motor &= ~((1<<P_Solenoid) |(1<<P_Pump));
}


void Motor_Adjust()
{
	PORTB |= (1<<PB7);                              // Pull up resistors enable on Down
	PORTE |=  ((1<<PE3) | (1<<PE2));				//PE3 = Right; PE2 = Left
	MotorInit();
	//Down Button
	while(bit_is_set(PINB, PB7))
	{
		// Left Button
		if(bit_is_clear(PINE,PE3))
			MotorOnBack();
		//Right Button
		else if(bit_is_clear(PINE,PE2))
			MotorOnForward();
		else
			MotorOff();
	}
}